package web.servlet.pet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import domain.Pet;

import service.PetServiceImpl;

public class FindPetByManyConditionServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");

		// 获取表单数据
		String petId = request.getParameter("petId");
		String petName = request.getParameter("petName");
		String petSpecies = request.getParameter("petSpecies");
		String petBirthday = request.getParameter("petBirthday");
		String ownerId = request.getParameter("ownerId");
		String doctorId = request.getParameter("doctorId");

		// 调用业务逻辑

		PetServiceImpl ps = new PetServiceImpl();
		List<Pet> list = ps.findPetByConditions(petId, petName, petSpecies, petBirthday, ownerId, doctorId);

		// 分发转向
		request.setAttribute("pets", list);// 把list放入request对象中
		request.getRequestDispatcher("/admin/pet/list.jsp").forward(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

}
